//
//  MCOrderListSectionFooterView.swift
//  StoreManage
//
//  Created by MC on 2017/12/21.
//  Copyright © 2017年 MC. All rights reserved.
//

import UIKit

class MCOrderListSectionFooterView: UIView {
    
    var model = MCOrderListFatherModel() {
        didSet {
            timeLabel.text = model.createTime
            
            var freightStr = ""
            
            if model.freight.intValue == 0 {
                freightStr = " (免运费)"
            } else {
                freightStr = " (含运费\(MCString_judgemantDecimalsIsZero(figure: model.freight.intValue)))"
            }
            
            let actualMoneyStr = "共" + model.totalQuantity.stringValue + "件,合计:"
            + MCString_judgemantDecimalsIsZero(figure: model.totalFee.intValue) + freightStr
            
            
            let range = NSRange.init(location: 6 + model.totalQuantity.stringValue.count, length: MCString_judgemantDecimalsIsZero(figure: model.totalFee.intValue).count)
            
            
            actualMoneyLabel.attributedText = actualMoneyStr.MCAttributedString_color(color: UIColor.MCMain, range: range)
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.MCGray_light
        setUpSubViews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUpSubViews() {
        
        
        self.addSubview(bgView)
        bgView.snp.remakeConstraints { (make) ->Void in
            make.edges.equalTo(self).inset(UIEdgeInsetsMake(0, 0, 5, 0))
        }
        
        bgView.addSubview(timeLabel)
        timeLabel.snp.updateConstraints { (make) -> Void in
            make.centerY.equalTo(bgView)
            make.right.equalTo(bgView).offset(-15)
        }
        
        bgView.addSubview(actualMoneyLabel)
        actualMoneyLabel.snp.remakeConstraints { (make) ->Void in
            make.centerY.equalTo(bgView)
            make.left.equalTo(bgView).offset(15)
        }
        
        
    }

    lazy var bgView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.white
        return view
    }()
    
    public lazy var timeLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(12)
        label.textColor = UIColor.MCGray
        return label
    }()
    
    public lazy var actualMoneyLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(14)
        label.textColor = UIColor.MCWords
        return label
    }()
    
}
